package com.ding.service;

import com.ding.entity.RuleInfo;
import com.ding.mapper.RuleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ding
 * @date 2021/6/4 16:48
 */

@Service
public class RuleService {
    @Resource
    private RuleMapper ruleMapper;

    public List<RuleInfo> getAllRules() {
        return ruleMapper.selectAll();
    }

    public void addRule(String rule) {
        RuleInfo ruleInfo = new RuleInfo();
        ruleInfo.setContent(rule);
        ruleMapper.insert(ruleInfo);
    }

    public void deleteRule(Long id) {
        ruleMapper.deleteByPrimaryKey(id);
    }

    public void update(RuleInfo ruleInfo) {
        ruleMapper.updateByPrimaryKey(ruleInfo);
    }

    public String getRuleById(Long i) {
        return ruleMapper.selectByPrimaryKey(i).getContent();
    }
}
